#include "snake.h"
#include "GraphicsManager.h"
#include "FontManager.h"
#include "InputManager.h"
#include "core.h"



//CVideogameProcess::CVideogameProcess()
//{
//
//}

CSnake::~CSnake()
{
	
}

void CSnake::Init()
{	 

}	 
	 
void CSnake::Deinit()
{	 
	 
}	 
	 
void CSnake::Update(float dt,float fps)
{
	m_deltaT=dt;
	m_fps=fps;
	
	if(m_deltaAccum>3)
	{
		m_speed*=2;
		m_deltaAccum=0;
	}
	else m_deltaAccum+=dt;
	

	if(CORE->GetInputManager()->IsUpDown(IDV_KEYBOARD,KEY_UP)) m_CurrDir=UP;
	if(CORE->GetInputManager()->IsUpDown(IDV_KEYBOARD,KEY_DOWN)) m_CurrDir=DOWN;
	if(CORE->GetInputManager()->IsUpDown(IDV_KEYBOARD,KEY_LEFT)) m_CurrDir=LEFT;
	if(CORE->GetInputManager()->IsUpDown(IDV_KEYBOARD,KEY_RIGHT)) m_CurrDir=RIGHT;

	switch(m_CurrDir)
	{
	case UP:
		m_CurrPos.y-=m_speed*m_deltaT;
		break;
	
	case DOWN:
		m_CurrPos.y+=m_speed*m_deltaT;
		break;

	case RIGHT:
		m_CurrPos.x+=m_speed*m_deltaT;
		break;
	case LEFT:
		m_CurrPos.x-=m_speed*m_deltaT;
		break;
	
	}

	
	if(m_CurrPos.x<0)  m_alive=false;
	if(m_CurrPos.x>CORE->GetGraphicsManager()->GetScreenRes().x)	m_alive=false;
	if(m_CurrPos.y<0)  m_alive=false;
	if(m_CurrPos.y>CORE->GetGraphicsManager()->GetScreenRes().y)	m_alive=false;

}

void CSnake::RenderScene()
{
	

}

void CSnake::RenderScene2D()
{

	
	CORE->GetGraphicsManager()->EnableAlphaBlend();
	CColor white=colWHITE;

	white.SetAlpha(0.5);

	if (m_alive) CORE->GetGraphicsManager()->DrawRectangle2D(Vect2i((uint32)m_CurrPos.x,(uint32)m_CurrPos.y),20,20,white,0,0,white);
	else CORE->GetFontManager()->DrawDefaultText(100,100,colWHITE,"YOU LOSE!!");

	CORE->GetGraphicsManager()->DisableAlphaBlend();

	
}

uint32		CSnake::RenderDebugInfo		()
{
	uint32 l_yaccum;
	CFontManager* fm=CORE->GetFontManager();


	l_yaccum=CProcess::RenderDebugInfo();
	l_yaccum+=fm->DrawDefaultText(10,l_yaccum,colWHITE,"Pos_X = %.2f",m_CurrPos.x);
	l_yaccum+=fm->DrawDefaultText(10,l_yaccum,colWHITE,"Pos_Y = %.2f",m_CurrPos.y);
	l_yaccum+=fm->DrawDefaultText(10,l_yaccum,colWHITE,"Speed = %.2f",m_speed);
	l_yaccum+=fm->DrawDefaultText(10,l_yaccum,colWHITE,"%.2f secs on this lvl",m_deltaAccum);
	l_yaccum+=fm->DrawDefaultText(10,l_yaccum,colWHITE,"%f", m_fps);
	return l_yaccum;

}